<template>
    <div id="operateTable">
        <span v-for="(option,index) in options">
            <el-button
                 v-if="index<2 ||(index === 2 && options.length<4)"
                 :style="option.style"
                 class="operate_button"
                 @click="clickFn(option.click)"
                 :type="option.type">{{option.label}}</el-button>

        </span>
        <el-dropdown v-if="options.length>3"
                     @command="handleCommand"
                     trigger="click"
                     class="operate_dropDown">
            <el-button type="primary">
                {{$t('common.more')}}
            </el-button>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                        v-if="index>1"
                        :command='index'
                        v-for="(option,index) in options">
                        {{option.label}}
                </el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
    </div>
</template>

<script>
    export default {
        name: "operate",
        props: {
            options: {
                type: Object,
                default() {
                    return {}
                }
            },
        },
        methods: {
            clickFn(fn) {
                if (!fn || !fn.length) {
                    return
                }
                fn[0](...fn.slice(1))
            },
            handleCommand(index){
                this.options[index].click[0](...this.options[index].click.slice(1))
            }
        }
    }
</script>

<style scoped>
    .operate_button {
        margin-left: 5px;
    }
    .operate_dropDown {
        margin-left: 5px;
    }
</style>